#include <isr.h>
#include <bwio.h>
#include <defs.h>
#include <ts7200.h>
#include <timer.h>
#include <vic.h>

void WakeAwaiters( sched *s, td *task, int eventid, int data ) {
  int i = s->waiters[eventid];
  if (i == -1) {
    return;
  }
  s->waiters[eventid] = -1;
  s->tasks[i].ret = data;
  s->tasks[i].state = STATE_READY;
  PqPushBack( &(s->queues[MAX_PRI]), &(s->tasks[i]) );
}

void DefaultHandler( sched *s, td *task ) {
  // We received an interrupt that our system doesn't handle; do nothing
}

void TimerHandler( sched *s, td *task ) {
  timer *const timer3 = (timer*)( TIMER3_BASE );
  timer3->clear = 0;
  WakeAwaiters(s, task, EVENT_TIMER, SUCCESS);
}
